use wd_run::{Input, TaskInfo};

pub struct  Run;

#[wd_run::async_trait]
impl wd_run::Task for Run {
    fn info(&self) -> TaskInfo {
        TaskInfo::new("run","run application")
            .register_arg("-c","./config.toml","config file path")
            .register_arg("-l",3usize,"max limil proccess")
    }

    async fn run(&self,mut input:Input) -> wd_run::Result<()> {
        let config_file_path:String = input.load("c").unwrap();
        println!("init: config file path ---> {}",config_file_path);
        let limit = input.load::<usize>("-l").unwrap();
        println!("max limit:{}",limit);
        for _ in 0..limit{
            println!("run application success");
            tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
        }
        Ok(())
    }

    async fn exit(&self,_input:Input) -> wd_run::Result<()> {
        Err(anyhow::anyhow!("work stream unormal"))
    }
}